Array.prototype.random=function(){
    return this[Math.floor(Math.random()*this.length)];
};
Array.prototype.insert=function(site,element){
	return this.splice(site,0,element);
};
Array.prototype.indexOf=function(keyword){
	for (var i=0;i<this.length ;i++ ){
		if (this[i]==keyword){
			return i;
		}
	}
	return -1;
};
Array.prototype.remove=function(keyword){
	if (this.index(keyword)){
		this.splice(this.index(keyword),1);
	}
	if (!isNaN(keyword)){
		this.splice(keyword,1);
	}
};
Array.prototype.filter=function(){
	this.sort();
	for (var i=this.length-1;i>=0 ;i-- ){
		for (var j=0;j<i ;j++ ){
			if (this[j]==this[i]){
				this.splice(j,1);
			}
		}
	}
};
Array.prototype.del=function(n){
	if(isNaN(n)||n>this.length||n<0){return false;}
　　this.splice(n,1);
}
Array.prototype.repeat=function(){
	this.sort();
	var a=[];
	for (var i=this.length-1;i>=0 ;i-- ){
		for (var j=0;j<i ;j++ ){
			if (this[j]==this[i]){
				a.push(this[j]);
			}
		}
	}
	return a;
};

String.prototype.random=function(){
	return this[Math.floor(Math.random()*this.length)];
};
String.prototype.cap=function(){
	return this.replace(this[0],this[0].toUpperCase());
};
String.prototype.decode=function(){
	return this.replace(/&#(x)?([^&]{1,5});?/g,function($, $1, $2){
		return String.fromCharCode(parseInt($2, $1 ? 16 : 10));
	});
};
String.prototype.hexEncode=function(){
	var res = [];
	for (var i=0;i<this.length ;i++ ){
		res[i] = this.charCodeAt(i).toString(16);
	}	
	return "&#" + String.fromCharCode(0x78) + res.join(";&#" + String.fromCharCode(0x78)) + ";";
};
String.prototype.encode=function(){
	var res = [];
	for (var i=0;i<this.length ;i++ ){
		res[i] = this.charCodeAt(i);
	}	
	return "&#" + res.join(";&#") + ";";
};
String.prototype.encode2=function(){
	var r = "",c;
	for (var i = 0; i < this.length; i++){
		c = this.charCodeAt(i);
		r += (c<32||c==38||c>127)?("&#" + c + ";"):this.charAt(i);
	}
	return r;
};
String.prototype.translate=function(dict){
	if (dict[this]){
		return dict[this];
	}
	else if (this.match(/ |_/)){
		var str = this.replace(/ |_/,'_')
		var arr = str.split('_');
		var s = [];
		for (i=0;i<arr.length ;i++ ){
			s.push(arr[i].translate(dict));
		}
		return s.join('');
	}
	else {
		return this;
	}
};
var range=function(){
	var s = [];
	var start,end,step;
	switch (arguments.length){
		case 1:
			start=0;
			end=arguments[0];
			step=1;
			break;
		case 2:
			start=arguments[0];
			end=arguments[1]+start;
			step=1;
			break;
		case 3:
			start=arguments[0];
			step=arguments[2];
			end=arguments[1]*step+start;
			break;
	}
	for (var i=start;step>0?i<end:i>end ;i += step ){
		s.push(i);
	}
	return s;
};
Math.rand=function(start,end,mode){
	var num = start+this.random()*(end-start);
	if (mode=='int'){
		return this.floor(num);
	}
	if (mode=='float' || !mode){
		return num;
	}
	if (mode=='string'){
		return String(num);
	}
};
Object.prototype.property=function(){
	var arr = [];
	for (var x in this){
		if (typeof this[x] != 'function'){
			arr.push(x);
		}
	}
	return arr;
};

var Hash = function(){};
Hash.prototype = {
	constructor: Hash,
	add: function(k, v){
		if (!this.hasOwnProperty(k)) {
			this[k] = v;
		}
	},
	remove: function(k){
		if (this.hasOwnProperty(k)) {
			delete this[k];
		}
	},
	update: function(k, v){
		this[k] = v;
	},
	has: function(k){
		var type = typeof k;
		if (type === 'string' || type === 'number') {
			return this.hasOwnProperty(k);
		} 
		else if (type === 'function' && this.some(k)) {
			return true;
		}
		return false;
	},
	clear: function(){
		for (var k in this) {
			if (this.hasOwnProperty(k)) {
				delete this[k];
			}
		}
	},
	empty: function(){
		for (var k in this) {
			if (this.hasOwnProperty(k)) {
				return false;
			}
		}
		return true;
	},
	each: function(fn){
		for (var k in this) {
			if (this.hasOwnProperty(k)) {
				fn.call(this, this[k], k, this);
			}
		}
	},
	map: function(fn){
		var hash = new Hash();
		for (var k in this) {
			if (this.hasOwnProperty(k)) {
				hash.add(k, fn.call(this, this[k], k, this));
			}
		}
		return hash;
	},
	filter: function(fn){
		var hash = new Hash();
		for (var k in this) {}
	},
	join: function(split){
		split = split !== undefined ? split : ',';
		var rst = [];
		this.each(function (v) {
			rst.push(v);
		});
		return rst.join(split);
	},
	every: function(fn){
		for (var k in this) {
			if (this.hasOwnProperty(k)) {
				if (!fn.call(this, this[k], k, this)) {
					return false;
				}
			}
		}
		return true;
	},
	some: function(fn){
		for (var k in this) {
			if (this.hasOwnProperty(k)) {
				if (fn.call(this, this[k], k, this)) {
					return true;
				}
			}
		}
		return false;
	},
	find: function(k){
		var type = typeof k;
		if (type === 'string' || type === 'number' && this.has(k)) {
			return this[k];
		}
		else if (type === 'function') {
			for (var _k in this) {
				if (this.hasOwnProperty(_k) && k.call(this, this[_k], _k, this)) {
					return this[_k];
				}
			}
		}
		return null;
	}
};

hash = {
	additiveHash:function(key,prime){
		var hash=key.length;
		for (var i=0; i<key.length; i++){
			hash += key.charAt(i);
		}
		return (hash % prime);
	},
	rotatingHash:function(key, prime){
		var hash=key.length;
		for (var i=0; i<key.length; ++i){
			hash = (hash<<4)^(hash>>28)^key.charAt(i);
		}
		return (hash % prime);
	}
};

var Random=function(){};
Random.prototype={
	constructor: Random,
	random:function(){
		return Math.random();
	},
	randint:function(){
		for (var i=0;i<arguments.length ;i++ ){
			arguments[i] = parseInt(arguments[i]);
			if (isNaN(arguments[i])){
				alert('type of argument is number');
				return;
			}
		}
		if (arguments.length==1){
			return Math.floor(this.random()*arguments[0]);
		}
		if (arguments.length>1){
			return arguments[0] + this.randint(arguments[1]-arguments[0]);
		}
	},
	uniform:function(){
		for (var i=0;i<arguments.length ;i++ ){
			arguments[i] = parseFloat(arguments[i]);
			if (isNaN(arguments[i])){
				alert('type of argument is number');
				return;
			}
		}
		if (arguments.length==1){
			return this.random()*arguments[0];
		}
		if (arguments.length>1){
			return arguments[0] + this.uniform(arguments[1]-arguments[0]);
		}
	},
	randrange:function(){
		for (var i=0;i<arguments.length ;i++ ){
			arguments[i] = parseInt(arguments[i]);
			if (isNaN(arguments[i])){
				alert('type of argument is number');
				return;
			}
		}
		var start = 0;
		var stop = arguments[0];
		var step = 1;
		switch(arguments.length){
			case 1:
			    break;
			case 2:
				start = arguments[0];
				stop = arguments[1];
			    break;
			case 3:
				start = arguments[0];
				stop = arguments[1];
				step = arguments[2];
			    break;
		}
		var array = []
		for (var i=start;i<=stop ;i += step){
			array.push(i);
		}
		return this.choice(array);
	},
	choice:function(array){
		return array[this.randint(array.length)];
	},
	shuffle:function(array){
		if (typeof(array)!='object'){
			alert('type of argument is array');
			return;
		}
		return array.sort(function(a,b){return 0.5-Math.random();});
	}
};